import { observable, action, autorun,toJS } from 'mobx';
import {WeaTools} from "ecCom"
import objectAssign from 'object-assign';
import {message,Modal} from 'antd';
import isEqual from 'lodash/isEqual';
import {WeaTableNew,WeaForm} from 'comsMobx'
const {TableStore} = WeaTableNew;
import MineCptStore from "./mineCptStore"
import * as  Apis from '../apis/cptCard';
import * as Cpt_Apis from '../apis/capital'
import {ShareStore } from './shareStore'
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

class CptCardStore extends  MineCptStore{
	@observable	tabDatas = [];

    @observable selectTabKey = "1"
	 
    @observable loading = false;
    @observable capitalid ="";
	@observable cptname= "资产";
	//统计报告
	@observable staticForm = new WeaForm();
	@observable staticCondition = [];

	@observable shareRightMenu = [];
	@observable isShowShare = false;
	@observable shareTableStore = new TableStore();
	@observable shareStore = new ShareStore();

	@observable verified = false;
	@observable hasRight = false; //权限
	@observable appDetachDisableAll =false;
	 
	@observable mapDialogVisible = false;//地图弹出框

    @action 
    //设置选中按钮
    changeTab=(key)=>{
	   this.selectTabKey = key;
	   if(key == "5"){  //统计报告
			this.staticForm = new WeaForm();
			this.staticCondition = [];
			this.loading = true;
			Apis.getCptStatistics({capitalid:this.capitalid}).then(data=>{
				this.staticCondition = data.fieldinfo;
				this.staticForm && !this.staticForm.isFormInit && this.staticForm.initFormFields(data.fieldinfo);
				this.loading = false;
			})
	    }
	    if(key == "3"){
			this.getFlowLogList({capitalid:this.capitalid});  //流转日志列表
			this.getFlowCondition({capitalid:this.capitalid});  //流转日志高级搜索
	    }
	    if(key == "4"){
			this.getModifyList({capitalid:this.capitalid});  //变更记录列表
			this.getModifyCondition({capitalid:this.capitalid});  //变更记录高级搜索
	    }
	    if( key == "2"){  //共享
			this.getCptShareList();
			Cpt_Apis.getCardRightMenu({capitalid:this.capitalid,tabkey:1}).then(data=>{
				this.shareRightMenu = data.rightMenus;
			})
	    }
       
    }

    getCptTabs=(params={})=>{
		this.loading = true;
		this.capitalid = params.capitalid;
        Apis.getTabDatas(params).then(data=>{
			if(!data.isright && typeof(data.isright) !== "undefined"){
				this.hasRight = data.isright;
				this.verified = true;
			}else{
				this.hasRight = true;
				this.verified = true;
				this.tabDatas = data.tabdatas ;
				this.loading = false;
			}
        })
	}
	//共享
	getCptShareList = (params={})=>{
		this.loading = true;
		Apis.getCptShareList({capitalid:this.capitalid,...params}).then(data=>{
			this.shareTableStore.getDatas(data.sessionkey,  params.current || 1);
			this.loading = false;
			this.appDetachDisableAll = data.appDetachDisableAll;
		})
	}
	//共享删除
	doDeteleShare= (params) =>{
		let {selectedRowKeys} = this.shareTableStore;
		if(selectedRowKeys.length>0){
			this.deteleShare(`${toJS(selectedRowKeys)}`);
		}else{
			Modal.info({
				title:  getLabel(15172,'系统提示'),
				content:getLabel('125014',"请至少选择一条数据!"),
			})
		}
	}
	deteleShare=(ids)=>{
		let that = this;
		Modal.confirm({
			title:  getLabel(15172,'系统提示'),
			content: getLabel(83600,'您确认要删除吗？'),
			onOk() {
				Apis.deteleShare({id:ids,}).then(data=>{
					that.getCptShareList();
				})
			},
			onCancel() {},
		  })
	}
	showAddShareModal=(bool)=>{
		this.isShowShare = bool;
	}
	//添加共享
	addShare=(params={})=>{
		Cpt_Apis.addCptShare({capitalid:this.capitalid,...params}).then(data=>{
			if(data.msg==''){
				this.getCptShareList();
				this.isShowShare = false;
				message.success(getLabel('385412',"添加共享成功！"));
			}else{
				message.error(data.msg);
				this.isShowShare = false;
			}
		})
	}
	//guihuai
	doGiveback=(params)=>{
		Cpt_Apis.doCptManager(params).then(data=>{
            if(data.msg==''){
                message.success(getLabel(83560,'归还成功！'));
				this.getCptInfo({...params,viewtype:'view'});
				window.opener._table.reLoad();
			}else{
				Modal.error({
					title:  getLabel(15172,'系统提示'),
					content: data.msg,
				});
			}
        }).catch(err=>message.error(err))
	}
	//送修
	
	checkRight = (params) => {
		Cpt_Apis.checkRight({...params,viewScope : "Maintenance"}).then(data=>{
			if(data.noRight){
				this.hasRight = false;
				this.verified = true;
			}else{
				this.hasRight = true;
				this.verified = true;
				this.getCptInfo({...params});
			}
		})
		
	}

	@action
	setMapDialogVisible = (v)=>{
		this.mapDialogVisible = v;
	}

}
const cptCardStore = new CptCardStore()
export default cptCardStore;